<template>
	<view class="home">
		<!-- 自定义导航栏 -->
		<navbar></navbar>
		<!-- 类别栏 -->
		<tab :tab="tabList" @tab="tab" :tabindex="tabindex"></tab>
		<!-- 列表栏 -->
		<view class="home-list">
			<list :list="tabList" @change="change" :tabindex="tabindex" ></list>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [],
				tabindex:0
			}
		},
		onLoad() {
			uni.$on("labelChange",()=>{
				this.tabList=[]
				this.tabindex=0 
				this.getlabel()
			})
			this.getlabel()
		},
		methods: {
			//子组件向父组件传值
			tab(data) {
				//设置tab和list联动的tabindex索引 
				this.tabindex=data.index				 
			},
			change(current){
				//设置tab和list联动的tabindex索引
				this.tabindex=current				 
			},
			
			
			getlabel() {
				//调用封装的方法执行云函数 
				this.$api.get_label({
					name: "get_label"
				}).then((res) => {
					
					const {data}=res 
					data.unshift({
						name:"全部"
					})
					this.tabList=data 
				})
				/* this.$api.get_label().then((res)=>{
					const {data}=res
					this.tabList=data
				}) */
				//调用云函数方法 已封装方法
				/* uniCloud.callFunction({
					name:"get_label"
				}).then((res)=>{
					const {result}=res
					//console.log(res.result)
					this.tabList=result.data
				}) */
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column; //flex垂直布局
		flex: 1;		
		overflow:  hidden;
		.home-list{
			flex: 1;
			overflow: hidden;
			//border: 1px #007AFF solid;
		}
	}
</style>
